<template>
  <div class="video-preview" @click="onClick">
    <div class="video-preview__content">
      <slot>
        <div v-if="removable" class="close-icon-wrap" @click.stop="remove">
          <van-icon name="plus" />
        </div>
        <video :enable-auto-rotation="true" :src="src" object-fit="fit" />
      </slot>
    </div>
  </div>
</template>

<script>
import { Icon } from 'vant'

export default {
  components: {
    [Icon.name]: Icon
  },
  props: {
    src: {
      type: String,
      default: ''
    },
    removable: {
      type: Boolean,
      default: true
    }
  },
  methods: {
    remove() {
      this.$emit('remove')
    },
    onClick(e) {
      e.stopPropagation()
      this.$emit('click')
    }
  }
}
</script>

<style lang="less">
.video-preview {
  padding-bottom: 30px;
  .video-preview__content {
    position: relative;
    width: 100%;
    height: 400px;
    box-sizing: border-box;
    overflow: hidden;
    vertical-align: bottom;
    border-radius: 12px;
    border: 1px dashed #f5f5f5;
  }

  video {
    max-height: 400px;
    width: 100%;
  }

  .close-icon-wrap {
    position: absolute;
    top: 0;
    right: 0;
    z-index: 100;
    width: 60px;
    height: 60px;
    border-radius: 0 12px 0 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(255, 255, 255, .4);

    .van-icon {
      font-size: 50px;
      font-weight: bold;
      color: #fff;
      transform: rotate(45deg);
    }
  }
}
</style>
